﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Cau2
{
    class SinhVienDAL
    {
        public SinhVienDAL() { }
        public DataTable DocDanhSachSinhVien()
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=(local);Initial Catalog=qlsv; User Id=sa; Password=sa";
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from sinhvien", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            return dt;
        }
        public void XoaSV(string masv)
        {
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = "Data Source=(local);Initial Catalog=qlsv; User Id=sa; Password=sa";
            conn.Open();
            SqlCommand cmd = new SqlCommand("delete from sinhvien where masv ='" + masv + "'", conn);
            cmd.ExecuteNonQuery();
        }
        public void ThemSinhVien(string masv, string hosv, string tensv,
                       string gioitinh, string ngaysinh, string makhoa)
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=(local);Initial Catalog=qlsv; User Id=sa; Password=sa";
            conn.Open();
            SqlCommand cmd = new SqlCommand("insert into sinhvien values ('" + masv + "',N'" + hosv + "',N'" + tensv + "',N'" + gioitinh + "','" + ngaysinh + "',N'" + makhoa + "')", conn);
            cmd.ExecuteNonQuery();
        }
    }
}